package com.acwing.partition12;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/2/9 17:02
 */
public class AC1124骑马修栅栏 {

    private static final int N = 510, M = 1100;
    private static int[][] graph = new int[N][N];
    private static int[] stk = new int[M], d = new int[N];

    private static int cnt = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int m = Integer.parseInt(reader.readLine());
        for (int i = 0; i < m; i++) {
            String[] ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]);
            graph[a][b]++;
            graph[b][a]++;
            d[a]++;
            d[b]++;
        }
        //无向图找到一个起点，度数为奇数就是欧拉路径，度数全部都为偶数就是欧拉回路
        int start = 1;
        for (int i = 1; i < N; i++) {
            if ((d[i] & 1) == 1) {
                start = i;
                break;
            }
        }
        dfs(start);
        for (int i = cnt; i > 0; i--) writer.write(stk[i] + "\n");
        writer.flush();
    }

    private static void dfs(int u) {
        for (int i = 1; i < N; i++) {
            if (graph[u][i] > 0) {
                graph[u][i]--;
                graph[i][u]--;
                dfs(i);
            }
        }
        stk[++cnt] = u;
    }
}
